package com.qyhl.webtv.module_live.teletext.mixlive;


import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.live.MixListBean;
import com.qyhl.webtv.module_live.common.LiveUrl;

import java.util.List;

/**
 * Created by qyhl on 2018/1/30.
 */

public class MixLiveListModel implements MixLiveListContract.MixLiveModel {
    private MixLiveListPresenter mPresenter;

    public MixLiveListModel(MixLiveListPresenter mPresenter) {
        this.mPresenter = mPresenter;
    }


    /**
     * 获取混合列表
     *
     * @param newsId
     * @param type   1 视频 2音频  空 混合
     */
    @Override
    public void getList(final String newsId, String type) {

        EasyHttp.get(LiveUrl.GET_MEDIA_LIST)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("type", type)
                .params("proId", newsId)
                .execute(new SimpleCallBack<List<MixListBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if ("0".equals(newsId)) {
                            if (e.getCode() == 202) {
                                mPresenter.setError(2, "暂无任何内容！");
                            } else {
                                mPresenter.setError(4, "解析异常，加载失败！");
                            }
                        } else {
                            if (e.getCode() == 202) {
                                mPresenter.setError(3, "no more");
                            } else {
                                mPresenter.setError(5, "解析异常，加载失败！");
                            }
                        }
                    }

                    @Override
                    public void onSuccess(List<MixListBean> mixListBeans) {
                        if ("0".equals(newsId)) {
                                if (mixListBeans != null && mixListBeans.size() > 0) {
                                    mPresenter.setList(mixListBeans, false);
                                } else {
                                    mPresenter.setError(2, "暂无任何内容！");
                                }
                        } else {
                                if (mixListBeans != null && mixListBeans.size() > 0) {
                                    mPresenter.setList(mixListBeans, true);
                                } else {
                                    mPresenter.setError(3, "no more");
                                }
                        }
                    }
                });

    }
}
